<template>
    <el-popover
        v-model:visible="visible"
        :width="width ? width - 2: undefined"
        :show-arrow="false"
        :offset="-33"
        :hide-after="0"
        placement="bottom-start"
        trigger="click"
        popper-class="cell-textarea-popover"
        @before-leave="handleBeforeLeave">
        <el-input
            v-model="text"
            :spellcheck="false"
            :autosize="{ minRows: 1, maxRows: 10 }"
            style="width: 100%;"
            type="textarea"
            placeholder="请输入内容">
        </el-input>
        <template #reference>
            <div class="handle"> {{ text }} </div>
        </template>
    </el-popover>
</template>

<script setup lang="ts">
import { ref } from 'vue';
defineProps({
    width: Number
})
const visible = ref(true)
const text = defineModel()
const emit = defineEmits(['leave'])
const handleBeforeLeave = () => {
    emit('leave')
}
</script>

<style scoped lang="scss">
.handle {
    display: flex;
    align-items: center;
    width: 100%;
    cursor: pointer;
    padding: 0 10px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    height: 32px;
    line-height: 30px;
    color: #bbb;
    border: 1px solid #fff;
}
</style>

<style lang="scss">
.cell-textarea-popover{
    padding: 0 !important;
    box-shadow: none !important;
    .el-textarea__inner{
        padding: 5px 10px;
    }
}
</style>